#include"ThreadPool.h"
#include<iostream>
#include<assert.h>
using namespace std;
using Task = std::function<void()>;

std::mutex mx;
void func() {
	this_thread::sleep_for(std::chrono::milliseconds(20));
}
int main() {
	ThreadPool<Task, ArrayBlockingQueue<Task*>> threadPool(5, 10, 500, std::unique_ptr<ArrayBlockingQueue<Task*>>(new ArrayBlockingQueue<Task*>(200)));
	int success = 0;
	int total = 300;
	for (int i = 0; i < total; ++i) {
		Task task = std::bind(func);
		bool flag = threadPool.execute(task);
		std::cout << (flag ? "success" : "failed") << std::endl;
		success += flag;
		std::cout << threadPool.workerCount() << std::endl;
	}
	std::cout << "success/total: " << success << "/" << total << std::endl;
	std::this_thread::sleep_for(std::chrono::milliseconds(5000));
	std::cout << threadPool.workerCount() << std::endl;
}